package scau.mis4.chanyulin.service.Impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import scau.mis4.chanyulin.dao.IGoodDetailMapper;
import scau.mis4.chanyulin.dao.IStockMapper;
import scau.mis4.chanyulin.entity.GoodDetail;
import scau.mis4.chanyulin.service.IGoodDetailService;
import java.util.List;

/**
 * Created by cyl on 2018/03/27.
 * GoodDetail Service实现
 */
@Service
public class GoodDetailServiceImpl extends AbstractBaseService<GoodDetail> implements IGoodDetailService {

    @Autowired
    private IGoodDetailMapper goodDetailMapper;
    @Autowired
    private IStockMapper stockMapper;

    public List<GoodDetail> findAll() {
        return goodDetailMapper.findAllGoodDetail();
    }

    public int delete(Object detailId) {
        List<GoodDetail> goodDetailList = findByProperties(detailId.toString(), "id");
        for (GoodDetail gd:goodDetailList) {
            String stockId = gd.getStockId();
            stockMapper.deleteByPrimaryKey(stockId);
            goodDetailMapper.deleteByPrimaryKey(detailId);
        }
        return 0;
    }

    public GoodDetail findByKey(Object detailId) {
        return goodDetailMapper.findGoodDetailById(detailId.toString());
    }

    @Override
    public List<GoodDetail> findByGoodId(String goodId) {
        return goodDetailMapper.findGoodDetailByGoodId(goodId);
    }

}
